<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2017/12/19
 * Time: 15:24
 * 删除栏目
 */
//后台登陆控制
include_once('admin_global.php');
$db->Get_user_shell_check($uid, $shell);   //检测用户是否登录
$db->Get_user_type_check($uid, $shell);    //检测用户权限

//删除栏目
$id=$_GET['id'];   //获取栏目ID
//查看该栏目下是否有子栏目
$sql="SELECT * FROM category WHERE catePID=$id";
$query=$db->query($sql);
$num=$db->db_num_rows($query);
if($num<=0){
    $sql1 = "DELETE FROM news WHERE newsCID=$id";          //从news表中删除该栏目下的文章
    $sql2 = "DELETE FROM category WHERE id=$id";           //从category表中删除该栏目
    $query1 = $db->query($sql1);
    $query2 = $db->query($sql2);
    if (($query1 == true) and ($query2 = true)) {
        echo "<script>alert('栏目删除成功！');window.location.href='listCate.php';</script>";
    } else {
        echo "<script>alert('栏目删除失败！');history.go(-1);</script>";
    }
}else{
    echo "<script>alert('该栏目下还有子栏目，必须先删除子栏目才能删除该栏目！');history.go(-1);</script>";
}